# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Jameson Pugh <imntreal@gmail.com>

pkgname=jc
pkgver=1.23.6
pkgrel=1
pkgdesc='Converts the output of popular command-line tools and file-types to JSON'
arch=('any')
url='https://github.com/kellyjonbrazil/jc'
license=('MIT')
depends=(
  'python'
  'python-pygments'
  'python-ruamel-yaml'
  'python-xmltodict'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-wheel'
  'python-setuptools'
)
_commit='249d93f15c877855c08454aa5c34905bc6c27f35'
source=("$pkgname::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build(){
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  python -m unittest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md EXAMPLES.md
  cp -vr docs "$pkgdir/usr/share/doc/$pkgname"

  # man page
  install -vDm644 -t "$pkgdir/usr/share/man/man1" man/jc.1

  # license
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/$pkgname-$pkgver.dist-info/LICENSE.md" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
}
